<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <script src="../modules/js/common.js"></script>
</head>
<body>
<div class="caption" align="center">
    <h1>欢迎登陆</h1>
    用户名:<input id="username"><br>
    密 &nbsp;&nbsp;&nbsp;码:<input id="password"><br>
    <span><button class="btn-info" onclick="login()" >登录</button></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <span><button class="btn-info" onclick="goback()">返回</button></span>
</div>

<script>

    function login(){
        let username=$("#username").val();
        let password=$("#password").val();
        let url=`http://localhost:8080/user/login/${username}/${password}`
        if(username==""||password==""){
            alert("用户名或密码不能为空");
            return;
        }
        $.ajax({
            url:url,
            success(result){
                if(result.state==1){
                    $.cookie("username",username,{path: "/"});
                    alert("登录成功");
                    location.href="http://localhost:8080";
                }else {
                    alert(result.message);
                }
            }
        })
    }

    function goback(){
        window.location.href="http://localhost:8080";
    }
</script>
</body>
</html>